local addonName, IWonew = ...

BagToolClass = {}
BagToolClass.__index = BagToolClass

function BagToolClass:new()
  local instance = setmetatable({}, BagToolClass)
	return instance
end

function BagToolClass:Debug()
  -- C_Container.PickupContainerItem(0, 1)
  -- C_Container.UseContainerItem(0, 1, "unitToken", Enum.BankType.Account)
  -- local itemID = C_Container.GetContainerItemID(0, 1)
  -- print(itemID)
  print("BagToolClass:Debug")
  self:MoveMoneyToAccountBank()
end

function BagToolClass:DeleteFHJItems()
  local deleteIds = {188694, 44794, 44792, 45073, 44803, 151806, 44800, 151804, 6833}
  local deleteNames = {"春日花袋", "春季兔脚", "开花的树枝", "春季花朵", "春季头饰", "端庄的裙子", "春季长袍", "黑色礼服短裤", "白色礼服衬衣"}
  local items = IWonew.GetAllBagItems()
  local deleteItems = {}
  for i = 1, #items do
    if IWonew.contains(deleteNames, items[i].itemName) then
      table.insert(deleteItems, items[i])
    end
  end
  if #deleteItems == 0 then
    print("删除完毕")
    return
  end
  C_Container.PickupContainerItem(deleteItems[1].bagID, deleteItems[1].slotID)
  DeleteCursorItem()
end

function BagToolClass:DeleteMengYueItems()
  local deleteIds = {180765, 186482, 186591, 186593, 186515, 181821, 186487, 186621, 186524, 186503, 182332, 186476, 186635, 186580, 186507, 180722, 186493, 187280, 186473, 186497}
  local deleteNames = {"的回忆"}
  local items = IWonew.GetAllBagItems()
  local deleteItems = {}
  for i = 1, #items do
    if IWonew.contains(deleteIds, items[i].itemID) or IWonew.StringPartInList(items[i].itemName, deleteNames) then
      table.insert(deleteItems, items[i])
    end
  end
  if #deleteItems == 0 then
    print("删除完毕")
    return
  end
  C_Container.PickupContainerItem(deleteItems[1].bagID, deleteItems[1].slotID)
  DeleteCursorItem()
end

function BagToolClass:GetBagMoney()
  local money = GetMoney()
  local gold = floor(money / 1e4)
  local silver = floor(money / 100 % 100)
  local copper = money % 100
  print(("You have %dg %ds %dc"):format(gold, silver, copper))
  return {gold = gold, silver = silver, copper = copper}
end

function BagToolClass:MoveMoneyToAccountBank()
  local money = self:GetBagMoney()
  local movedGold = 0
  if money.gold > 100 then
    C_Bank.DepositMoney(Enum.BankType.Account, (money.gold - 100) * 10000)
    movedGold = money.gold - 100
  end
  print("移动金币：" .. movedGold)
end

function BagToolClass:MoveCraftItemsToAccountBankByNames()
  local items = IWonew.GetAllBagItems()
  local names = {
    "心核合金", "镔爪合金", "回音助熔剂", "风暴之尘", "粼光碎片", "耀辉水晶"
  }
  for i = 1, #items do
    local itemName = items[i].itemName
    if (not items[i].isBound) and IWonew.contains(names, itemName) then
      C_Container.UseContainerItem(items[i].bagID, items[i].slotID, "unitToken", Enum.BankType.Account)
    end
  end
end

-- function BagToolClass:MoveCraftItemsToAccountBank()
function BagToolClass:MoveCraftItemsToAccountBank()
  local items = IWonew.GetAllBagItems()
  local ignoreItems = {
    "附魔羊皮纸", "晶脉粉末", "专注奇思瓶剂", "铋棒", "暗月套牌：共生", "热流铁砧",
  }
  for i = 1, #items do
    local itemName = items[i].itemName
    if (not items[i].isBound) and (not IWonew.contains(ignoreItems, itemName)) then
      C_Container.UseContainerItem(items[i].bagID, items[i].slotID, "unitToken", Enum.BankType.Account)
    end
  end
end

function BagToolClass:CheckHasCraftRegentBox()
  local items = IWonew.GetAllBagItems()
  local box_count = 0
  for i = 1, #items do
    local itemName = items[i].itemName
    if itemName == "工匠商盟支出" then
      box_count = box_count + 1
    end
  end
  if box_count <= 0 then
    IWonew.CreateTextFrame(80, "匠F", 640, 0)
  end
end



local BagTool_instance = nil
function CreateBagToolInstance()
  if BagTool_instance == nil then
    BagTool_instance = BagToolClass:new()
  end
  return BagTool_instance
end

-- /dump MoveMoneyToAccountBank()
function MoveMoneyToAccountBank()
  CreateBagToolInstance():MoveMoneyToAccountBank()
end

-- /dump MoveCraftItemsToAccountBank()
function MoveCraftItemsToAccountBank()
  CreateBagToolInstance():MoveCraftItemsToAccountBank()
end

function MoveCraftItemsToAccountBankByNames()
  CreateBagToolInstance():MoveCraftItemsToAccountBankByNames()
end

function MoveCraftItemsAndMoneyToAccountBank()
  local instance = CreateBagToolInstance()
  instance:MoveMoneyToAccountBank()
  instance:MoveCraftItemsToAccountBank()
  -- /dump _G["GuildBankFrame"]:Show()
  -- /script GuildBankFrame:Show()
  -- /script BankFrame:Show()
  -- /dump _G["BankFrame"]:Show()
  -- /dump ShowUIPanel(GuildBankFrame)
  -- /script BankFrame:Show()
  -- /run ToggleFrame(GuildBankFrame)
  -- /dump C_Bank.CanViewBank(2)
end

function CheckHasCraftRegentBox()
  local instance = CreateBagToolInstance()
  instance:CheckHasCraftRegentBox()
end

function DeleteFHJItems()
  local instance = CreateBagToolInstance()
  instance:DeleteFHJItems()
end

function DeleteMengYueItems()
  local instance = CreateBagToolInstance()
  instance:DeleteMengYueItems()
end
